﻿
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DBUtility;//Please add references
namespace DAL
{
	/// <summary>
	/// 数据访问类:T_PublicEmployeeHJJL
	/// </summary>
	public partial class T_PublicEmployeeHJJL
	{
		public T_PublicEmployeeHJJL()
		{}
		#region  BasicMethod



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public long Add(Model.T_PublicEmployeeHJJL model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_PublicEmployeeHJJL(");
			strSql.Append("EmployeeID,EmployeeName,SJ,JBDW,JSLB,JSMC,QDMC,HJCH)");
			strSql.Append(" values (");
			strSql.Append("@EmployeeID,@EmployeeName,@SJ,@JBDW,@JSLB,@JSMC,@QDMC,@HJCH)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@EmployeeID", SqlDbType.NVarChar,30),
					new SqlParameter("@EmployeeName", SqlDbType.NVarChar,10),
					new SqlParameter("@SJ", SqlDbType.NVarChar,20),
					new SqlParameter("@JBDW", SqlDbType.NVarChar,50),
					new SqlParameter("@JSLB", SqlDbType.NVarChar,30),
					new SqlParameter("@JSMC", SqlDbType.NVarChar,50),
					new SqlParameter("@QDMC", SqlDbType.NVarChar,30),
					new SqlParameter("@HJCH", SqlDbType.NVarChar,40)};
			parameters[0].Value = model.EmployeeID;
			parameters[1].Value = model.EmployeeName;
			parameters[2].Value = model.SJ;
			parameters[3].Value = model.JBDW;
			parameters[4].Value = model.JSLB;
			parameters[5].Value = model.JSMC;
			parameters[6].Value = model.QDMC;
			parameters[7].Value = model.HJCH;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt64(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Model.T_PublicEmployeeHJJL model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_PublicEmployeeHJJL set ");
			strSql.Append("EmployeeID=@EmployeeID,");
			strSql.Append("EmployeeName=@EmployeeName,");
			strSql.Append("SJ=@SJ,");
			strSql.Append("JBDW=@JBDW,");
			strSql.Append("JSLB=@JSLB,");
			strSql.Append("JSMC=@JSMC,");
			strSql.Append("QDMC=@QDMC,");
			strSql.Append("HJCH=@HJCH");
			strSql.Append(" where FID=@FID");
			SqlParameter[] parameters = {
					new SqlParameter("@EmployeeID", SqlDbType.NVarChar,30),
					new SqlParameter("@EmployeeName", SqlDbType.NVarChar,10),
					new SqlParameter("@SJ", SqlDbType.NVarChar,20),
					new SqlParameter("@JBDW", SqlDbType.NVarChar,50),
					new SqlParameter("@JSLB", SqlDbType.NVarChar,30),
					new SqlParameter("@JSMC", SqlDbType.NVarChar,50),
					new SqlParameter("@QDMC", SqlDbType.NVarChar,30),
					new SqlParameter("@HJCH", SqlDbType.NVarChar,40),
					new SqlParameter("@FID", SqlDbType.BigInt,8)};
			parameters[0].Value = model.EmployeeID;
			parameters[1].Value = model.EmployeeName;
			parameters[2].Value = model.SJ;
			parameters[3].Value = model.JBDW;
			parameters[4].Value = model.JSLB;
			parameters[5].Value = model.JSMC;
			parameters[6].Value = model.QDMC;
			parameters[7].Value = model.HJCH;
			parameters[8].Value = model.FID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(long FID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_PublicEmployeeHJJL ");
			strSql.Append(" where FID=@FID");
			SqlParameter[] parameters = {
					new SqlParameter("@FID", SqlDbType.BigInt)
			};
			parameters[0].Value = FID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string FIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_PublicEmployeeHJJL ");
			strSql.Append(" where FID in ("+FIDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.T_PublicEmployeeHJJL GetModel(long FID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 FID,EmployeeID,EmployeeName,SJ,JBDW,JSLB,JSMC,QDMC,HJCH from T_PublicEmployeeHJJL ");
			strSql.Append(" where FID=@FID");
			SqlParameter[] parameters = {
					new SqlParameter("@FID", SqlDbType.BigInt)
			};
			parameters[0].Value = FID;

			Model.T_PublicEmployeeHJJL model=new Model.T_PublicEmployeeHJJL();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.T_PublicEmployeeHJJL DataRowToModel(DataRow row)
		{
			Model.T_PublicEmployeeHJJL model=new Model.T_PublicEmployeeHJJL();
			if (row != null)
			{
				if(row["FID"]!=null && row["FID"].ToString()!="")
				{
					model.FID=long.Parse(row["FID"].ToString());
				}
				if(row["EmployeeID"]!=null)
				{
					model.EmployeeID=row["EmployeeID"].ToString();
				}
				if(row["EmployeeName"]!=null)
				{
					model.EmployeeName=row["EmployeeName"].ToString();
				}
				if(row["SJ"]!=null)
				{
					model.SJ=row["SJ"].ToString();
				}
				if(row["JBDW"]!=null)
				{
					model.JBDW=row["JBDW"].ToString();
				}
				if(row["JSLB"]!=null)
				{
					model.JSLB=row["JSLB"].ToString();
				}
				if(row["JSMC"]!=null)
				{
					model.JSMC=row["JSMC"].ToString();
				}
				if(row["QDMC"]!=null)
				{
					model.QDMC=row["QDMC"].ToString();
				}
				if(row["HJCH"]!=null)
				{
					model.HJCH=row["HJCH"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select FID,EmployeeID,EmployeeName,SJ,JBDW,JSLB,JSMC,QDMC,HJCH ");
			strSql.Append(" FROM T_PublicEmployeeHJJL ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" FID,EmployeeID,EmployeeName,SJ,JBDW,JSLB,JSMC,QDMC,HJCH ");
			strSql.Append(" FROM T_PublicEmployeeHJJL ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_PublicEmployeeHJJL ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.FID desc");
			}
			strSql.Append(")AS Row, T.*  from T_PublicEmployeeHJJL T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "T_PublicEmployeeHJJL";
			parameters[1].Value = "FID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

